<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <style type="text/css">

        .container {
            margin-top: 100px;

        }

    </style>
</head>
<body>
<div class="container">

    <div class="row" id="vueBox">
        <div class="col-md-6">
            <form class="form-inline" role="form" style="padding-left: 250px;">
                <div class="form-group" style="padding-left: 20px;">
                    <label>图书分类:</label>
                    <select class="form-control" v-model="categoryListId">
                        <option value="0">全部</option>
                        <option v-for="(item,index) in categoryList.data" :value="item.id">{{item.name}}</option>
                    </select>
                </div>
                <div class="form-group" style="padding-left: 20px;">
                    <button type="button" class="btn btn-primary" @click="selEntryAll(1)">查询
                    </button>
                </div>

            </form>
        </div>
        <div class="col-md-4 text-right">
            <a href="add_entry.html" class="btn btn-primary">新增电子图书</a>
        </div>

        <br/>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>图书编号</th>
                <th>图书名称</th>
                <th>图书摘要</th>
                <th>上传人</th>
                <th>上传时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(item,index) in entryList.data.list">
                <td>{{item.id}}</td>
                <td>{{item.title}}</td>
                <td>{{item.summary}}</td>
                <td>{{item.uploaduser}}</td>
                <td>{{item.createdate}}</td>
                <td>
                    <button class="btn btn-success" @click="to_update_entry(item.id)">修改</button>
                    <button class="btn btn-danger" @click="deleteEntry(item.id)">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
        <ul class="pagination">
            <li v-show="entryList.data.hasPreviousPage"><a href="#"
                                                           @click="selEntryAll(entryList.data.prePage)">&laquo;</a></li>
            <li :class="{active:entryList.data.pageNum==i}" v-for="i in entryList.data.navigatepageNums">
                <a href="#"  @click="selEntryAll(i)">{{i}}</a>
            </li>
            <li v-show="entryList.data.hasNextPage"><a href="#"
                                                       @click="selEntryAll(entryList.data.nextPage)">&raquo;</a></li>
        </ul>
        <br/>
    </div>
</div>

</body>
</html>
<script type="text/javascript">
    var vue = new Vue({
        el: '#vueBox',
        data: {
            categoryList: [],
            categoryListId: "0",
            entryList: []
        }, methods: {
            selEntryAll: function (pageNum) {
                axios.get("/selBycategoryId", {
                    params: {
                        pageNum: pageNum,
                        categoryId: this.categoryListId
                    }
                }).then(res => this.entryList = res.data);
            }


        },
        mounted() {
            axios.get("/getCategoryList").then(res => this.categoryList = res.data);
            this.selEntryAll();
        }


    })


</script>